﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    /// <summary>
    /// jy61姿态仪的各项参数、系数、计算值
    /// </summary>
    public class JY61PParam
    {
        #region 参数
        //加速度参数
        public short IAccelerationX { get; set; }
        public short IAccelerationY { get; set; }
        public short IAccelerationZ { get; set; }
        public short ITemp { get; set; }//温度

        //角速度参数
        public short IAngularVelocityX { get; set; }
        public short IAngularVelocityY { get; set; }
        public short IAngularVelocityZ { get; set; }
        public short IVolt { get; set; }//电压

        //角度参数
        public short IAngleX { get; set; }
        public short IAngleY { get; set; }
        public short IAngleZ { get; set; }
        public short IVersion { get; set; }//版本号

        #endregion

        #region 系数
        //加速度系数
        private const float AccelerationFactor = 16.00f / 32768.00f;
        private const float AccelerationOffset = 0.00f;//偏移量

        //角速度系数
        private const float AngularVelocityFactor = 2000.00f / 32768.00f;
        private const float AngularVelocityOffset = 0.00f;

        //角度系数
        private const float AngleFactor = 180.00f / 32768.00f;
        private const float AngleOffset = 0.00f;

        //温度系数
        private const float TempFactor = 1.00f / 100.00f;
        private const float TempOffset = 0.00f;

        //电压系数
        private const float VoltFactor = 1.00f / 100.00f;
        private const float VoltOffset = 0.00f;

        //版本号系数
        private const float VersionFactor = 1.00f;
        private const float VersionOffset = 0.00f;

        #endregion

        #region 计算值
        //计算得加速度:速度参数*系数+偏移量
        public float AccelerationX
        {
            get { return IAccelerationX * AccelerationFactor + AccelerationOffset; }//IAccelerationX已经是向左移动8位组合好的数据
        }
        public float AccelerationY
        {
            get { return IAccelerationY * AccelerationFactor + AccelerationOffset; }
        }
        public float AccelerationZ
        {
            get { return IAccelerationZ * AccelerationFactor + AccelerationOffset; }
        }


        //计算角速度
        public float AngularVelocityX
        {
            get { return IAngularVelocityX * AngularVelocityFactor + AngularVelocityOffset; }
        }
        public float AngularVelocityY
        {
            get { return IAngularVelocityY * AngularVelocityFactor + AngularVelocityOffset; }
        }
        public float AngularVelocityZ
        {
            get { return IAngularVelocityZ * AngularVelocityFactor + AngularVelocityOffset; }
        }

        //角度
        public float AngleX
        {
            get { return IAngleX * AngleFactor + AngleOffset; }
        }
        public float AngleY
        {
            get { return IAngleY * AngleFactor + AngleOffset; }
        }
        public float AngleZ
        {
            get { return IAngleZ * AngleFactor + AngleOffset; }
        }
        


        //温度
        public float Temp
        {
            get { return ITemp * TempFactor + TempOffset; }
        }

        //电压
        public float Volt
        {
            get { return IVolt * VoltFactor + VoltOffset; }
        }

        //版本号
        public float Version
        {
            get { return IVersion * VersionFactor + VersionOffset; }
        }

        #endregion
    }
}
